﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：4424edb2-b7c4-439d-b9d9-bc8699215018
 * 文件名：Label
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/6/24 20:34:56
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
/// 文本控件
/// </summary>
public sealed class Text : ControlBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    internal Text()
    {
    }

    public override string Id { get; set; }
    public override string Title { get; set; }
    internal TextType Type { get; set; }

    internal TextSizeType Size { get; set; }

    internal TextTagType TagType { get; set; }

    public override string ConverToHtml()
    {
        StringBuilder sb = new StringBuilder();

        Param parms = new Param();

        //if (Type == TextType.Default)
        //{
        //    sb.AppendLine($"<el-text class=\"mx-1\" size=\"{Size.GetDescription()}\" >{Content}</el-text>");
        //}
        //else
        //{
        //    sb.AppendLine($"<el-text class=\"mx-1\" size=\"{Size.GetDescription()}\" type=\"{Type.GetDescription()}\">{Content}</el-text>");
        //}

        if (Type != TextType.Default)
        {
            parms.Add($"type=\"{Type.GetDescription()}\"");
        }

        if (Size != TextSizeType.Default)
        {
            parms.Add($"size=\"{Size.GetDescription()}\"");
        }

        if (TagType != TextTagType.Default)
        {
            parms.Add($"tag=\"{TagType.GetDescription()}\"");

            //if(TagType== TextTagType.Sub||TagType== TextTagType.Sup)
            //    parms.Add($"tag=\"{TagType.GetDescription()}\"");
        }

        sb.AppendLine($"<el-text class=\"mx-1\" {parms} >{Title}</el-text>");

        return sb.ToString();
    }
}

public enum TextType
{
    /// <summary>
    ///
    /// </summary>
    [Description("default")]
    Default,

    /// <summary>
    ///
    /// </summary>
    [Description("primary")]
    Primary,

    /// <summary>
    ///
    /// </summary>
    [Description("success")]
    Success,

    /// <summary>
    ///
    /// </summary>
    [Description("info")]
    Info,

    /// <summary>
    ///
    /// </summary>
    [Description("warning")]
    Warning,

    /// <summary>
    ///
    /// </summary>
    [Description("danger")]
    Danger,
}

public enum TextSizeType
{
    /// <summary>
    ///
    /// </summary>
    [Description("default")]
    Default,

    /// <summary>
    ///
    /// </summary>
    [Description("large")]
    Large,

    /// <summary>
    ///
    /// </summary>
    [Description("small")]
    Small,
}

/// <summary>
/// 文本的Tag标签
/// </summary>
public enum TextTagType
{
    /// <summary>
    /// 默认
    /// </summary>
    [Description("default")]
    Default,

    /// <summary>
    /// 常规
    /// </summary>
    [Description("p")]
    P,

    /// <summary>
    /// 加粗
    /// </summary>
    [Description("b")]
    B,

    /// <summary>
    /// 倾斜
    /// </summary>
    [Description("i")]
    I,

    /// <summary>
    /// 上标
    /// </summary>
    [Description("sub")]
    Sub,

    /// <summary>
    /// 下标
    /// </summary>
    [Description("sup")]
    Sup,

    /// <summary>
    /// 下划线
    /// </summary>
    [Description("ins")]
    Ins,

    /// <summary>
    /// 删除线
    /// </summary>
    [Description("del")]
    Del,

    /// <summary>
    /// 标黄标记
    /// </summary>
    [Description("mark")]
    Mark
}

public static partial class App
{
    /// <summary>
    /// 创建文本
    /// </summary>
    /// <param name="content"></param>
    /// <param name="type"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    public static Text CreateText(string content, TextType type = TextType.Default, TextSizeType size = TextSizeType.Default, TextTagType tag = TextTagType.Default)
    {
        Text label = new Text()
        {
            Id = GenerateId(),
            Type = type,
            Title = content,
            Size = size,
            TagType = tag
        };

        return label;
    }

    /// <summary>
    /// 创建文本
    /// </summary>
    /// <param name="content"></param>
    /// <param name="type"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    public static Text CreateText(Action<List<ControlBase>> content, TextType type = TextType.Default, TextSizeType size = TextSizeType.Default, TextTagType tag = TextTagType.Default)
    {
        List<ControlBase> controls = new List<ControlBase>();

        content?.Invoke(controls);

        if (controls == null || controls.Count == 0)
        {
            throw new Exception("需要传入内容！");
        }

        return CreateText(string.Join("\r\n", controls.Select(s => s.ConverToHtml())), type, size);
    }
}